/* 
 * File:   testme.c
 * Author: Baghomian, Arnold
 * Class: CS362
 * Random Testing Quiz 2
 *
 * Created on July 19, 2014, 7:13 PM
 */

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

 
char inputChar()
{
    // TODO: rewrite this function
    // only takes 1/4 second to reach state 9
    return rand()%256;
}

char *inputString()
{
    // TODO: rewrite this function
    static char word[10];
    // adding more chars increases time to finish
    // 27 characters gives 9 months to finish on average
    // I settled on 12 chars giving about 2 minutes
    // this tests the function very well anyway
    static char chars[]=".ZAB}rese t";
    int i;
    for (i = 0; i < 6; ++i)
        word[i] = chars[rand()%12];  // gives random of 10 chars including null from chars[]]
    
    return word;
    
   
}

void testme()
{
  int tcCount = 0;
  char *s;
  char c;
  int state = 0;
  while (1)
  {
    tcCount++;
    c = inputChar();
    s = inputString();
    printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state);

    if (c == '[' && state == 0) state = 1;
    if (c == '(' && state == 1) state = 2;
    if (c == '{' && state == 2) state = 3;
    if (c == ' '&& state == 3) state = 4;
    if (c == 'a' && state == 4) state = 5;
    if (c == 'x' && state == 5) state = 6;
    if (c == '}' && state == 6) state = 7;
    if (c == ')' && state == 7) state = 8;
    if (c == ']' && state == 8) state = 9;
    if (s[0] == 'r' && s[1] == 'e'
       && s[2] == 's' && s[3] == 'e'
       && s[4] == 't' && s[5] == '\0'
       && state == 9)
    {
      printf("error ");
      exit(200);
    }
  }
}


int main(int argc, char *argv[])
{
    srand(time(NULL));
    testme();
    return 0;
}
